import Vue from 'vue'
import VueRouter from 'vue-router'
import admin from "@/views/admin";
import {isLogin}from'@/utils/idnex'
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    component: admin,
    name: 'admin',
  },
  {
    path: '/Login',
    name: 'Login',
    component: () => import('@/views/Login/index'),
    meta:{
      roles:'*'//所有角色都可以访问
    }
  },

  {
    path: '/Nopemnission',
    name: 'Nopemnission',
    component: () => import('@/views/Nopemnission/permission'),
    meta:{
      roles:'*'//所有角色都可以访问
    }
  },


]

const router = new VueRouter({
  routes
})
// 登录鉴权
router.beforeEach((to, from, next) => {
  if (to.path !== '/Login') {
    if (isLogin()) {
      /*
        路由角色鉴权
      */
    next()

    } else {
      next('/Login')
    }
  } else {
    next()
  }
})

export default router
